#ifndef MENUVET
#define MENUVET

#include "general.h"
#include "vetores.h"
#include "savefile.h"

extern sistema ms;
extern fmmt estator, rotor, resul;
extern double cmd_simtstep;
extern grafico grafp, grafq, grafs, grafe, grafpt;
extern grafico grafwr, grafi, grafcosfi, grafdelta;
extern void controleRedisplay();

extern int janvetores;
extern bool showvetores;
extern bool deltag, cosfig, ig, wrg;
extern bool ptg, eg, sg, qg, pg, none;
extern bool ok, step;
extern void vetoresKeyboard(unsigned char key, int x, int y);

extern GLUI_Spinner *spine, *spinpt;

int menuvet, sube, subpt, subgraf, subsave;
bool realcevet=false;

void vetoresMenu(int id)
{
	bool oldst;
	double temp;
	switch(id)
	{
	case 0:
		break;
	case 1:
		ok=true;
		break;
	case 2:
		ok=false;
		break;
	case 3:	
		printf(MSG104);
		ms.setA(140);
		ms.setD((float)0.08);
		ms.setIEXC(IEXC_NOM);
		ms.setV(3688);
		ms.setWS(2*pi()*60);
		ms.setPT(PT_NOM);
		ms.setXS((float)1.105);
		ms.setH(2);
		ms.setRPS();
		ms.setTSTEP((float)cmd_simtstep);
		ms.init(0);
		grafi.init();grafi.setxaxislimit(10,0);
		grafdelta.init();grafdelta.setxaxislimit(10,0);
		grafcosfi.init();grafcosfi.setxaxislimit(10,0);
		grafwr.init();grafwr.setxaxislimit(10,0);
		grafpt.init();grafpt.setxaxislimit(10,0);
		grafe.init();grafe.setxaxislimit(10,0);
		grafp.init();grafp.setxaxislimit(10,0);
		grafq.init();grafq.setxaxislimit(10,0);
		grafs.init();grafs.setxaxislimit(10,0);
		spine->set_int_val(IEXC_NOM);
		spinpt->set_int_val((int)(PT_NOM/1000));
		break;
	case 4:
		realcevet=!realcevet;
		if(realcevet) {glutSetWindow(janvetores);glEnable(GL_LINE_SMOOTH);}
		else {glutSetWindow(janvetores);glDisable(GL_LINE_SMOOTH);}
		break;
	case 5:
		glutSetWindow(janvetores);
		glutHideWindow();
		showvetores=false;
		break;

	case 101:
		temp=ms.iexc;
		if(temp==IEXC_MIN) temp=0.05*IEXC_MAX;
		else temp*=1.2;
		if(temp>IEXC_MAX) temp=IEXC_MAX;
		spine->set_int_val((int)temp);
		ms.setIEXC(temp);
		break;
	case 102:	
		temp=ms.iexc;
		if(temp==IEXC_MIN) temp=0.01*IEXC_MAX;
		else temp*=1.1;
		if(temp>IEXC_MAX) temp=IEXC_MAX;
		spine->set_int_val((int)temp);
		ms.setIEXC(temp);
		break;
	case 103:	
		temp=ms.iexc;
		temp*=0.9;
		if(temp<IEXC_MIN) temp=IEXC_MIN;
		spine->set_int_val((int)temp);
		ms.setIEXC(temp);
		break;
	case 104:	
		temp=ms.iexc;
		temp*=0.8;
		if(temp<IEXC_MIN) temp=IEXC_MIN;
		spine->set_int_val((int)temp);
		ms.setIEXC(temp);
		break;

	case 201:
		temp=ms.pt;
		if(temp==PT_MIN) temp=0.05*PT_MAX;
		else temp*=1.2;
		if(temp>PT_MAX) temp=PT_MAX;
		spinpt->set_int_val((int)(temp/1000));
		ms.setPT(temp);
		break;
	case 202:	
		temp=ms.pt;
		if(temp==PT_MIN) temp=0.01*PT_MAX;
		else temp*=1.1;
		if(temp>PT_MAX) temp=PT_MAX;
		spinpt->set_int_val((int)(temp/1000));
		ms.setPT(temp);
		break;
	case 203:	
		temp=ms.pt;
		temp*=0.9;
		if(temp<PT_MIN) temp=PT_MIN;
		spinpt->set_int_val((int)(temp/1000));
		ms.setPT(temp);
		break;
	case 204:	
		temp=ms.pt;
		temp*=0.8;
		if(temp<PT_MIN) temp=PT_MIN;
		spinpt->set_int_val((int)(temp/1000));
		ms.setPT(temp);
		break;

	case 300:
	case 301:
	case 302:
	case 303:
	case 304:
	case 305:
	case 306:
	case 307:
	case 308:
	case 309:
		vetoresKeyboard(-300+'0'+id, 0,0);
		break;

	case 401:
		oldst=ok;
		ok=false;
		jansave(2);
		//ok=oldst;
		break;
	case 402:
		oldst=ok;
		ok=false;
		jansave(1);
		//ok=oldst;
		break;
	/*case 403: opcao retirada
		oldst=ok;
		ok=false;
		jansave(0);
		//ok=oldst;
		break;*/

	case 500:
		oldst=ok;
		ok=false;
		jansave(3);
		break;

	case 600:
		ms.vetorFE=!ms.vetorFE;
		ms.vetorFR=!ms.vetorFR;
		ms.vetorFRES=!ms.vetorFRES;
		glutPostRedisplay();
		break;
	}
}

void vetoresCreateMenu(void)
{
	sube=glutCreateMenu(vetoresMenu);
	glutAddMenuEntry("+ 20%",101);
	glutAddMenuEntry("+ 10%",102);
	glutAddMenuEntry("- 10%",103);
	glutAddMenuEntry("- 20%",104);
	
	subpt=glutCreateMenu(vetoresMenu);
	glutAddMenuEntry("+ 20%",201);
	glutAddMenuEntry("+ 10%",202);
	glutAddMenuEntry("- 10%",203);
	glutAddMenuEntry("- 20%",204);

	subgraf=glutCreateMenu(vetoresMenu);
	glutAddMenuEntry(MSG105,301);
	glutAddMenuEntry(MSG106,302);
	glutAddMenuEntry(MSG107,303);
	glutAddMenuEntry(MSG108,304);
	glutAddMenuEntry(MSG109,305);
	glutAddMenuEntry(MSG110,306);
	glutAddMenuEntry(MSG111,307);
	glutAddMenuEntry(MSG112,308);
	glutAddMenuEntry(MSG113,309);
	glutAddMenuEntry("",0);
	glutAddMenuEntry(MSG114,300);
	
	subsave=glutCreateMenu(vetoresMenu);
	glutAddMenuEntry(MSG115,401);
	glutAddMenuEntry(MSG116,402);
	//glutAddMenuEntry(MSG117,403); excluida...
		
	menuvet=glutCreateMenu(vetoresMenu);
	glutAddSubMenu(MSG93,sube);
	glutAddSubMenu(MSG94, subpt);
	glutAddSubMenu(MSG118,subgraf);
	glutAddMenuEntry(MSG119, 600);
	glutAddMenuEntry("",0);
	glutAddMenuEntry(MSG95,1);
	glutAddMenuEntry(MSG96,2);
	glutAddMenuEntry("",0);
	glutAddMenuEntry(MSG120, 500);
	glutAddSubMenu(MSG121,subsave);
	glutAddMenuEntry("",0);
	glutAddMenuEntry(MSG100, 3);
	glutAddMenuEntry("",0);
	glutAddMenuEntry(MSG101,4);
	glutAddMenuEntry(MSG102,5);

	glutAttachMenu(GLUT_RIGHT_BUTTON);
}

#endif
